//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Policy Injection Application Block
//===============================================================================

using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.Design;
using EntLibContrib.PolicyInjection.CallHandlers.Configuration.Design.Properties;

namespace EntLibContrib.PolicyInjection.CallHandlers.Configuration.Design
{
	/// <summary>
	/// A <see cref="ConfigurationNode"/> that represents the configuration
	/// of an <see cref="ThreadSafeCallHandler" /> in the Configuration
	/// Console.
	/// </summary>
	public class ThreadSafeCallHandlerNode : CallHandlerNode
	{
		#region Fields
		private string syncRoot;
		#endregion

		#region Properties
		/// <summary>
		/// ThreadSafe to use.
		/// </summary>
		/// <value>Get or set ThreadSafe.</value>
		[SRDescription("ThreadSafeDescription", typeof(Resources))]
		[SRCategory("CategoryGeneral", typeof(Resources))]
		public string SyncRoot
		{
			get { return syncRoot; }
			set { syncRoot = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Create a new <see cref="ThreadSafeCallHandlerNode"/> with default settings.
		/// </summary>
		public ThreadSafeCallHandlerNode()
			: this(new ThreadSafeCallHandlerData(Resources.ThreadSafeCallHandlerNodeName))
		{
		}

		/// <summary>
		/// Create a new <see cref="ThreadSafeCallHandlerNode"/> with the given settings.
		/// </summary>
		/// <param name="callHandlerData">Configuration information to initialize the node with.</param>
		public ThreadSafeCallHandlerNode(ThreadSafeCallHandlerData callHandlerData)
			: base(callHandlerData)
		{
			SyncRoot = callHandlerData.SyncRoot;
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Converts the information stored in the node and generate
		/// the corresponding configuration element to store in
		/// an <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.IConfigurationSource"/>.
		/// </summary>
		/// <returns>
		/// Newly created <see cref="ThreadSafeCallHandlerData"/> containing
		/// the configuration data from this node.
		/// </returns>
		/// <remarks>
		/// Subclasses implement this method to return an instance of a concrete <see cref="T:Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.CallHandlerData"/> subclass.
		/// </remarks>
		public override CallHandlerData CreateCallHandlerData()
		{
			ThreadSafeCallHandlerData callHandlerData = new ThreadSafeCallHandlerData(Name);
			callHandlerData.SyncRoot = SyncRoot;

			return callHandlerData;
		}
		#endregion
	}
}
